<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="org.bson.Document" %>
<%@ page import="com.mongodb.client.*" %>
<%@ page import="java.util.regex.Pattern" %>
<%@ page import="org.bson.conversions.Bson" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.LinkedList" %>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>添加学生</title>
    <link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.4.1/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>

<%
    String url = "mongodb://g08:abc%408@mongo.zhledu.cn:27017/g08";
    MongoClient client = MongoClients.create(url);
    MongoIterable<String> names = client.listDatabaseNames();
    MongoDatabase g08 = client.getDatabase("g08");
    MongoCollection<Document> collection = g08.getCollection("student");
    String sno = request.getParameter("sno");
    Document query = new Document("sno", sno);
    final FindIterable<Document> list = collection.find(query).limit(1);
    Document student = new Document();
    for (Document s : list) {
        student = s;
        break;
    }

%>
<div class="container">
    <center>
        <h1>查看学生</h1>
    </center>
    <form class="form-horizontal" method="post" action="save.jsp">
        <div class="form-group">
            <label class="control-label col-sm-2">学号:</label>
            <div class="col-sm-4">
                <input id="sno" name="sno" class="form-control" value="<%=sno%>">
            </div>
            <label class="control-label col-sm-2"> 姓名:</label>
            <div class="col-sm-4">
                <input id="name" name="name" class="form-control" value="<%=student.getString("name")%>">
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-sm-2"> 身份证号:</label>
            <div class="col-sm-4">
                <input id="idCard" name="idCard" class="form-control" value="<%=student.getString("idCard")%>">
            </div>
            <label class="control-label col-sm-2"> 电话:</label>
            <div class="col-sm-4">
                <input id="phone" name="phone" type="tel" class="form-control" value="<%=student.getString("phone")%>">
            </div>
        </div>
        <div class="form-group">

            <label class="control-label col-sm-2"> 年龄:</label>
            <div class="col-sm-4">
                <input id="age" name="age" class="form-control" value="<%=student.getInteger("age")%>">
            </div>
            <label class="control-label col-sm-2"> 出生日期:</label>
            <div class="col-sm-4">
                <input id="birthDay" type="text" name="birthDay" class="form-control"
                       value="<%=student.getString("birthDay")%>">
            </div>
        </div>

        <div class="form-group">
            <label class="control-label col-sm-2"> 性别:</label>
            <div class="col-sm-4">
                <input id="sex" name="sex" class="form-control" value="<%=student.getString("sex")%>">
            </div>


            <label class="control-label col-sm-2"> 用户名:</label>
            <div class="col-sm-4">
                <input id="username" name="username" class="form-control" required
                       value="<%=student.getString("username")%>">
            </div>
        </div>

        <div class="form-group">
            <label class="control-label col-sm-2"> 电子邮件:</label>
            <div class="col-sm-4">
                <input id="email" name="email" type="email" class="form-control"
                       value="<%=student.getString("email")%>">
            </div>

            <label class="control-label col-sm-2"> 专业:</label>
            <div class="col-sm-4">
                <input id="major" name="major" class="form-control" value="<%=student.getString("major")%>">
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-sm-2"> 家庭地址:</label>
            <div class="col-sm-10">
                <textarea class="form-control" id="address" name="address"><%=student.getString("address")%></textarea>
            </div>
        </div>
    </form>
    <center>
        <button type="button" class="btn btn-primary glyphicon glyphicon-refresh" id="index">回首页</button>
    </center>
</div>


<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.1/jquery.min.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.4.1/js/bootstrap.min.js"></script>

<script>
    $("#index").on("click", function () {
        window.location.href = "index.jsp";
    })
</script>

<%
    client.close();
%>
</body>
</html>
